/**
 * 
 */
package info.niwota.webagent.util;

/**
 * @author qiangli
 * 
 */
public class WebUtils {
	private static final String ISHELL_PREFIX = "HI: ";
	private static final int ISHELL_PREFIX_LEN = ISHELL_PREFIX.length();
	private static final String LINE_SEP = ";";
	private static final String FIELD_SEP = ",";

	private WebUtils() {
	}

	/**
	 * Hotweb Address HI: 10.0.0.1, 10080;
	 * 
	 * @param s
	 * @return
	 */
	public static String[] parseAddress(String s) {
		if (s != null && s.startsWith(ISHELL_PREFIX)) {
			try {
				String[] sa = s.substring(ISHELL_PREFIX_LEN).split(LINE_SEP)[0]
						.split(FIELD_SEP);
				for (int i = 0; i < sa.length; i++) {
					sa[i] = sa[i].trim();
				}
				return sa;
			} catch (Exception e) {
				//
			}
		}
		return null;
	}

	public static String[] parseUri(String uri) {
		// ~pid/path
		if (uri.startsWith("/~")) {
			int idx = uri.indexOf("/", 1);
			String[] sa = new String[2];
			sa[0] = uri.substring(1, idx);
			sa[1] = uri.substring(idx);
			return sa;
		}
		return new String[] {null, uri};
	}

}
